<?php
namespace app\wechat\controller;
use app\model\Order;
use app\model\Users;
use app\model\Resources;
use app\model\Suggestion;
use app\model\SuggestResources;
use think\Config;
use think\Session;
use oss\QiniuCloud;

class UserController extends BaseController
{
    protected $user_id;
    public function _initialize()
    {
        parent::_initialize();
        $this->user_id = Session::get('user_id');
    }

    public function index(){
        $user = Users::get(['id'=>$this->user_id]);
        $this->assign('user',$user);
        return $this->fetch();
    }

    /**
     * 用户信息
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function detail(){
        $user = Users::get(['id'=>$this->user_id]);
        $this->assign('user',$user);
        return $this->fetch();
    }

    /**
     * post 编辑用户信息
     * @return array
     * @throws \think\exception\DbException
     */
    public function edit(){
        $data = $this->request->post();
        $user = Users::get(['id'=>$this->user_id]);
        $user->data($data);
        $user->save();
        return msgReturn(true,'修改成功');
    }

    /**
     * 历史订单
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function order(){
        $list = Order::where('user_id',$this->user_id)->order('id desc')->paginate(10);
        //$list = Order::all(['user_id' => $this->user_id]);
        $this->assign('list',$list);
        return $this->fetch();
    }

}
